<?php
    session_start();
    require_once dirname(__FILE__) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'html_generator.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_date.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_pager.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_matches.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php';

    $title = 'Home Page';

    $error_show = "";
    $username = "";
    $password = "";
    if (!empty($_POST)) {
        $username = filter_input(INPUT_POST, "txt_username");
        $password = filter_input(INPUT_POST, "txt_password");


        $result = api_security::login($username, $password);
        
        if ($result['user_login'] === 'logined') {
            api_security::update_last_login($result['id']);
            $_SESSION['user_login'] = 'logined';
            $_SESSION['user_info']  = $result;
            if ($result['role_id'] == 1) {
                lib_redirect::Redirect('/admin/index.php');
            } else {
                lib_redirect::Redirect('/index.php');
            }

        } else {
            $error_show = "Login failed.";
        }
    }

?>

<!DOCTYPE html>
<!-- IE SECTION -->

<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->

                     <!-- END IE SECTION -->
<html>
<head>
    <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php' ?>
</head>
<body>
<?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'header.php' ?>

<!-- Title -->
<div class="section section-black">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="calltoaction-wrapper">
                    <h3>Login</h3>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Title -->

<!-- List Matches -->
<div class="section">
    <div class="container">
        <div class="row">
            <div class="col-md-offset-3 col-sm-6">
                <div class="basic-login">
                    <form role="form" method="POST" action="?">
                        <?php
                            show_message("", $error_show, 0, 0);
                        ?>
                        <div class="form-group">
                            <label for="login-username"><i class="icon-user"></i> <b>Username</b></label>
                            <input class="form-control" name="txt_username" id="login-username" value="<?php echo $username; ?>" type="text" placeholder="">
                        </div>
                        <div class="form-group">
                            <label for="login-password"><i class="icon-lock"></i> <b>Password</b></label>
                            <input class="form-control" name="txt_password" id="login-password" value="<?php echo $password; ?>" type="password" placeholder="">
                        </div>
                        <div class="form-group">
                            <!--									<label class="checkbox">
                                                                    <input type="checkbox"> Remember me
                                                                </label>-->
                            <!--<a href="page-password-reset.html" class="forgot-password">Forgot password?</a>-->
                            <button type="submit" class="btn pull-right">Login</button>
                            <div class="clearfix"></div>
                        </div>
                    </form>
                </div>
            </div>
            <!--					<div class="col-sm-7 social-login">
                                    <p>Or login with your Facebook or Twitter</p>
                                    <div class="social-login-buttons">
                                        <a href="#" class="btn-facebook-login">Login with Facebook</a>
                                        <a href="#" class="btn-twitter-login">Login with Twitter</a>
                                    </div>
                                    <div class="clearfix"></div>
                                    <div class="not-member">
                                        <p>Not a member? <a href="page-register.html">Register here</a></p>
                                    </div>
                                </div>-->
        </div>
    </div>
</div>
<!-- End List Matches -->

<?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php' ?>
</body>
</html>